home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / circuits / pcb-1.000 / pcb-1 / pcb-1.3 / create_sed_script.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  1995-02-25  |  2KB  |  85 lines

  1. #! /bin/sh
  2. #
  3. #                             COPYRIGHT
  4. #   PCB, interactive printed circuit board design
  5. #   Copyright (C) 1994,1995 Thomas Nau
  6. #   This program is free software; you can redistribute it and/or modify
  7. #   it under the terms of the GNU General Public License as published by
  8. #   the Free Software Foundation; either version 2 of the License, or
  9. #   (at your option) any later version.
  10. #   This program is distributed in the hope that it will be useful,
  11. #   but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. #   GNU General Public License for more details.
  14. #   You should have received a copy of the GNU General Public License
  15. #   along with this program; if not, write to the Free Software
  16. #   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. #   Contact addresses for paper mail and Email:
  18. #   Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
  19. #   Thomas.Nau@rz.uni-ulm.de
  20. #   RCS: $Header: /sda4/users/nau/src/pcb/RCS/create_sed_script.sh,v 2.2 1994/10/29 17:38:23 nau Exp $
  21. #
  22. #
  23. # create a sed script used to create the application default resource file
  24. # and the man pages
  25. # Usage: create_sed_script.sh [imake defines]
  26. #
  27.  
  28. # some system need nawk
  29. #
  30. case `uname` in
  31.     SunOS)        AWK=nawk;;
  32.     *)            AWK=awk;;
  33. esac
  34.  
  35. # extract defines passed from Makefile and create sed script
  36. #
  37. while [ $# -gt 0 ]
  38. do
  39.     echo $1 | \
  40.     sed -e '/\//s//\\\//g' \
  41.         -e '/^-D\([A-Za-z0-9_]*\)=\(.*\)/s//\/\1\/s\/\/\2\/g/g' \
  42.         -e '/^[^\/]/d' \
  43.         -e '/"/s///g'
  44.     shift
  45. done
  46.  
  47. # get defines from const.h and add them to script
  48. # ignore comments and double '/' because they are used as seperator for
  49. # the sed command itself
  50. #
  51. sed -e '/\/\*.*\*\//s///g' \
  52.     -e '/\//s//\\\//g' \
  53.     -e '/[[:space:]]+/s// /g' \
  54.     -e '/"/s///g' const.h |
  55.     $AWK '
  56.         BEGIN    {
  57.             count = 0;
  58.         }
  59.         /^#define/    {
  60.             while(substr($0, length($0), 1) == "\\")
  61.             {
  62.                 line[count] = line[count] substr($0, 1, length($0)-1) " ";
  63.                 getline;
  64.             }
  65.             line[count] = line[count] $0;
  66.             count++;
  67.             next;
  68.         }
  69.         END    {
  70.             for (i = 0; i < count; i++)
  71.             {
  72.                 number = split(line[i], arg);
  73.                 printf("/%s/s//", arg[2]);
  74.                 for (a = 3; a < number; a++)
  75.                     printf("%s ", arg[a]);
  76.                 printf("%s/g\n", arg[a]);
  77.             }
  78.         }' 
  79.